# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/7/13 17:57
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/rpc_dao.git
# @File    : car_raw_info.py
# @Software: PyCharm
# @Version: 2.7.5
from . import Session
from .models import TCarprofile
from py3_utils import my_sqlalchemy
from sqlalchemy import and_


def add_car_profile(car):
	return my_sqlalchemy.common_insert(Session(), car, TCarprofile)


def get_car_profile(user_id, customer_id, license_no, vin_no, engine_no, register_date):
	session = Session()
	return session.query(TCarprofile).filter(and_(user_id == user_id),
	                                         and_(customer_id == customer_id),
	                                         and_(license_no == license_no),
	                                         and_(vin_no == vin_no),
	                                         and_(engine_no == engine_no),
	                                         and_(register_date == register_date)).first()


def get_carfile_list(user_id, customer_id):
	return Session().query(TCarprofile).filter(and_(user_id == user_id),
	                                           and_(customer_id == customer_id)).all()


def get_carfile_license_no_list(user_id, customer_id, license_no):
	return Session().query(TCarprofile).filter(and_(user_id == user_id),
	                                           and_(customer_id == customer_id),
	                                           and_(license_no == license_no)).all()
